<!--
  路由未找到组件 - 路由不存在提示
-->
<template>
  <div class="route-not-found-container">
    <!-- 路由内容区域 -->
    <div class="route-content">
      <!-- 路由图标 -->
      <div class="route-icon">
        <el-icon :size="120" color="#909399">
          <LocationInformation />
        </el-icon>
      </div>
      
      <!-- 路由信息 -->
      <div class="route-info">
        <h1 class="route-title">页面不存在</h1>
        <p class="route-message">{{ routeMessage }}</p>
        <p class="route-description">{{ routeDescription }}</p>
      </div>
      
      <!-- 操作按钮 -->
      <div class="route-actions">
        <el-button type="primary" size="large" @click="handleGoHome">
          返回首页
        </el-button>
        <el-button size="large" @click="handleGoBack">
          返回上页
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { 
  ref, 
  reactive, 
  onBeforeMount,
  onMounted, 
  onBeforeUpdate,
  onUpdated,
  onBeforeUnmount,
  onUnmounted,
  onErrorCaptured,
  nextTick 
} from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { LocationInformation } from '@element-plus/icons-vue'

// 组件名称
defineOptions({
  name: 'RouteNotFound'
})

// 路由实例
const router = useRouter()
const route = useRoute()

// 响应式变量声明（按照模板中的顺序）
const routeMessage = ref('抱歉，您访问的页面不存在')
const routeDescription = ref('请检查URL是否正确，或返回首页')

// 响应式对象
const routeInfo = reactive({
  currentPath: '',
  referer: '',
  accessTime: ''
})

// 响应函数声明（按照模板中的顺序）
/**
 * 返回首页
 */
const handleGoHome = () => {
  router.push('/')
}

/**
 * 返回上一页
 */
const handleGoBack = () => {
  if (window.history.length > 1) {
    router.go(-1)
  } else {
    router.push('/')
  }
}

// 样式函数声明
/**
 * 获取路由页面样式
 */
const getRouteStyle = () => {
  return {
    background: 'linear-gradient(135deg, #f0f2f5 0%, #d6d9dc 100%)'
  }
}

// 生命周期钩子
onBeforeMount(() => {
  // 组件挂载前执行的逻辑
  routeInfo.currentPath = route.path
  routeInfo.accessTime = new Date().toLocaleString()
  routeInfo.referer = document.referrer || '无来源页'
  
  // 更新路由信息
  routeMessage.value = `页面 "${route.path}" 不存在`
})

onMounted(() => {
  // 组件挂载后执行的逻辑
  console.log('路由未找到组件已加载')
})

onBeforeUpdate(() => {
  // 组件更新之前执行的逻辑
  nextTick(() => {
    // 在DOM更新之后执行的逻辑
  })
})

onUpdated(() => {
  // 组件更新之后执行的逻辑
})

onBeforeUnmount(() => {
  // 组件卸载前执行的逻辑
})

onUnmounted(() => {
  // 组件卸载后执行的逻辑
})

onErrorCaptured((err, instance, info) => {
  // 捕获来自后代组件的错误
  console.error('组件错误:', err, info)
  return false // 阻止错误继续向上传播
})
</script>

<style lang="less" scoped>
.route-not-found-container {
  // 路由未找到页面容器样式
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0f2f5 0%, #d6d9dc 100%);
  
  .route-content {
    // 路由内容区域样式
    text-align: center;
    padding: 60px 40px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    max-width: 500px;
    
    .route-icon {
      // 路由图标样式
      margin-bottom: 30px;
      display: flex;
      justify-content: center;
      
      .el-icon {
        animation: float 3s ease-in-out infinite;
      }
    }
    
    .route-info {
      // 路由信息样式
      margin-bottom: 40px;
      
      .route-title {
        font-size: 32px;
        font-weight: 600;
        color: #333;
        margin-bottom: 16px;
      }
      
      .route-message {
        font-size: 16px;
        color: #909399;
        margin-bottom: 12px;
        font-weight: 500;
      }
      
      .route-description {
        font-size: 14px;
        color: #666;
        line-height: 1.6;
      }
    }
    
    .route-actions {
      // 操作按钮样式
      display: flex;
      gap: 16px;
      justify-content: center;
      
      .el-button {
        min-width: 120px;
        height: 44px;
        font-size: 14px;
        border-radius: 8px;
        transition: all 0.3s ease;
        
        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
        }
      }
    }
  }
}

// 浮动动画
@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

// 响应式设计
@media (max-width: 768px) {
  .route-not-found-container {
    padding: 20px;
    
    .route-content {
      padding: 40px 20px;
      
      .route-info {
        .route-title {
          font-size: 24px;
        }
      }
      
      .route-actions {
        flex-direction: column;
        
        .el-button {
          width: 100%;
        }
      }
    }
  }
}
</style>